//
//  FBOrderListViewController.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/15.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "FBOrderListViewController.h"
#import "FBPayOrderViewController.h"
#import "FBOrderSlideView.h"
#import "FBOrderModel.h"


@interface FBOrderListViewController ()


@property (nonatomic,assign)NSInteger FBpage ;


@property (nonatomic,strong)FBOrderSlideView *segmentView;

@end

@implementation FBOrderListViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    [self setProperty];
    
    [self createUI];
    
    [self loadFBData:YES];
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden=YES;
    
}

-(void)setProperty{
    
    self.view.backgroundColor=RGB(255, 255, 255);
    
    [UIApplication sharedApplication].statusBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    self.navigationController.navigationBarHidden=YES;
    
    self.baseVcTitle = @"法币订单";
    
    _FBpage = 1;
    
}



-(void)createUI{
    
    WS(weakSelf);
    NSArray * arr =@[@"法币交易"];
    _segmentView  =  [FBOrderSlideView segmentControlViewWithFrame:CGRectMake(0, kStatusBarAndNavigationBarHeight, G_SCREENWIDTH, G_SCREENHEIGHT-kStatusBarAndNavigationBarHeight)];
    _segmentView.normalColor = RGB(102,102,102);
    _segmentView.selectedColor = MC_THEME_COLOR;
    _segmentView.SlideSelectedColor=MC_THEME_COLOR;
    _segmentView.titleArray = arr;
    _segmentView.selectedTitleArray = arr;
    [self.view addSubview:_segmentView];
    _segmentView.fbBlock = ^{
        
        weakSelf.FBpage ++;
        [weakSelf loadFBData:NO];
        
    };
    
    _segmentView.FBclickBlock = ^(FBAllOrderModel * _Nonnull model) {
        
        FBPayOrderViewController * VC = [[FBPayOrderViewController alloc]init];
        VC.order_sn = model.order_sn;
        [weakSelf.navigationController pushViewController:VC animated:YES];
        
    };
    
    
}




-(void)loadFBData:(BOOL)isNew{
    
    WS(weakSelf);
    if (isNew) {
        _FBpage=1;
    }
    NSString * URL = [NSString stringWithFormat:@"%@otcorder/getOrder",DEFAULTSEVERBASEURL];
    
    NSDictionary * Dic =@{
                          @"page":[NSString stringWithFormat:@"%ld",(long)_FBpage],
                          @"limit":@"10"
                          };
    [HUD showProgress:@"" inView:self.segmentView];
    
    [MOLoadHttpsData GetHttpDataWithUrlStr:URL Dic:Dic SuccessBlock:^(id  _Nonnull responseObject) {
        NSDictionary * dic = responseObject;
        
        NSString * code = [NSString stringWithFormat:@"%@",dic[@"code"]];
        if ([code isEqualToString:@"0"]) {
            NSDictionary * dicc = dic[@"data"];
            
            
            FBOrderModel * AllModel = [FBOrderModel sharedFBOrderModel];
            if (isNew) {
                [AllModel.FBMarray removeAllObjects];
            }
            NSMutableArray * marr = [[NSMutableArray alloc]init];
            for (NSDictionary *temp in dicc[@"list"]) {
                FBAllOrderModel * Model = [FBAllOrderModel mj_objectWithKeyValues:temp];
                [marr addObject:Model];
            }
            [AllModel.FBMarray addObjectsFromArray:marr];
            
            if (marr.count==0||marr.count<10) {
                weakSelf.segmentView.FBCell.tableView.mj_footer.hidden=YES;
            }else{
                weakSelf.segmentView.FBCell.tableView.mj_footer.hidden=NO;
            }
            //            NSLog(@"%@-----",AllModel.FBMarray);
            
            [weakSelf.segmentView.FBCell relayOutUI];
            
        }
        
        [weakSelf.segmentView.FBCell.tableView.mj_header  endRefreshing];
        [weakSelf.segmentView.FBCell.tableView.mj_footer  endRefreshing];
        
        [HUD dismissInView:weakSelf.segmentView];
        
    } FailureBlock:^(id  _Nonnull error) {
        
        [weakSelf.segmentView.FBCell.tableView.mj_header  endRefreshing];
        [weakSelf.segmentView.FBCell.tableView.mj_footer  endRefreshing];
        
        [HUD dismissInView:weakSelf.segmentView];

    }];
    
    
}



@end
